$('#reservation').daterangepicker({
        "startDate": "03/4/2017",
        "endDate": "03/05/2017"
}, function(start, end, label) {
        console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
});
//账户类型数据
var userTypeData = [
    {id:'-1',text:'全部'},
    {id:'普通账户',text:'普通账户'},
    {id:'黑铁会员',text:'黑铁会员'},
    {id:'黄金会员',text:'黄金会员'}
];
$(".user-type-select2").select2({
    data:userTypeData
})
//data tables展示数据
$('.query').click(function(){
    $('#user-table').dataTable().fnDestroy();
    var code = $('#code').val();
    var name = $('#name').val();
    var time = $('#reservation').val();
    var userType = $('.user-type-select2 option:selected').val();
    console.log(code+"="+name+"="+time+"="+userType);
    var params = "code="+code+"&name="+name+"&time="+time+"&userType="+userType;
    $('#user-table').DataTable({
        "processing":true,
        "serverSide":true,
        "searching":false,
        "bPaginate":false,
        "dDestroy":true,
        "ajax":AjaxPath.rootPath+"/user?"+params,
        "columns":[
            {"data":"code"},
            {"data":"name"},
            {"data":"notes"},
            {"data":"statusStr"},
            {"data":"userType"},
            {"data":"gmtCreateStr"},
            {"data":"gmtLastSigninStr"}
        ],
        "columnDefs" : [ {
// 定义操作列,######以下是重点########
            "targets" : 7,//操作按钮目标列
            "data" : null,
            "render" : function(data, type,row) {
                var id =  row.id;
                var status = row.status;
                var html = "<a href='/updateUser?id="+id+"' class='up btn btn-default btn-xs'> 编辑</a>"
                html += "<a href='' onclick='deleteUser("+id+")' class='down btn btn-default btn-xs'> 删除</a>"
                if(status==1){
                    html += "<a href='' onclick='updateUserStatus("+id+","+status+")' class='down btn btn-default btn-xs'>封存</a>"
                }else{
                    html += "<a href='' onclick='updateUserStatus("+id+","+status+")'  class='down btn btn-default btn-xs'>启封</a>"
                }
                return html;
            }
        } ],
    });
});
//封存
function updateUserStatus(id,status){
    $.ajax({
        type: 'POST',
        async:false,
        url : AjaxPath.rootPath+'/user/status/'+id+"/"+status,
        success : function(data){
            if(data.status == 200){
                alert("操作成功！");
            }else{
                alert(data.message);
            }
        },
        error:function(data){
            alert("操作失败！");
        }
    })
}
//删除数据
function deleteUser(id){
    if(confirm("确定要删除吗？")){
        $.ajax({
            type: 'DELETE',
            async:false,
            url : AjaxPath.rootPath+'/user/'+id,
            success : function(data){
                if(data.status == 200){
                    alert("删除成功！");
                    location.href="/";
                }else{
                    alert(data.message);
                }
            },
            error:function(data){
                alert("删除失败！");
            }
        })
    }

}






